package com.n9.qq.android.login.tlv;

import com.n9.qq.util.Util;

import java.util.Objects;

/**
 * @author ice
 * @since 2019/2/12 14:18
 */
public class Tlv0202 extends BaseTlv {

    public Tlv0202() {
        this.cmd = 0x0202;
    }

    public byte[] getData(byte[] bssidMd5, byte[] ssid) {
        if (Objects.isNull(bssidMd5)) {
            bssidMd5 = new byte[16];
        }
        if (Objects.isNull(ssid)) {
            ssid = new byte[0];
        }

        final int bssidMd5Len = Math.min(bssidMd5.length, 16);
        final int ssidLen = Math.min(ssid.length, 32);

        byte[] data = new byte[bssidMd5Len + 2 + 2 + ssidLen];
        int index = 0;

        Util.int16_to_buf(data, index, bssidMd5Len);
        index += 2;
        System.arraycopy(bssidMd5, 0, data, index, bssidMd5Len);
        index += bssidMd5Len;

        Util.int16_to_buf(data, index, ssidLen);
        index += 2;
        System.arraycopy(ssid, 0, data, index, ssidLen);

        return this.getBufData(data);
    }


}
